<template>  
    <view class="container">  
        <uni-list>  
            <uni-badge size="small" absolute="right" type="red"
             v-for="(item, index) in sortedList" 
             :key="item.id"
             :text="item.password">
                <uni-list-item
                :thumb="'/static' + item.icon"  
                thumbSize="lg"  
                :showArrow="true"  
                :title="item.username"
                :note="'电话：'+item.telephone"
                :clickable="true"
                @click="toPage(item.id)"
                >
                </uni-list-item>  
            </uni-badge>
        </uni-list>  
    </view>  
</template>  
  
<script>  
    export default {  
        data() {  
            return {
                list: []
            };  
        },
        computed: {
            sortedList() {
                return this.list.sort((a, b) => a.id - b.id);
            }
        },
        onLoad() {
            uni.request({
                url: 'http://localhost:8090/foodapp/user/list',
                method: 'POST',
                data: {},
                success: res => {
                    this.list = res.data.data;
                    console.log('获取到的学生列表：', this.list);
                }
            });
        },
        methods: {
            toPage(id){
                uni.navigateTo({
                    url:'../index/student?id='+id
                })
            }
        }
    };  
</script>  
  
<style>  
</style>
